Page({

  /**
   * 页面的初始数据
   */
  data: {
    files: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  // 选择图片
  chooseImage: function (e) {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        var files = res.tempFilePaths;
        wx.showLoading({
          title: '图片上传中'
        });
        wx.uploadFile({
          url: app.globalData.globalUrl + 'reserve/washcash/uploadPic',
          filePath: files[0],
          name: 'pic',
          success: function (res) {
            var data = res.data;
            if (typeof data != 'object') data = JSON.parse(data);
            if (data.code == 200) {
              var avatarUrl = app.globalData.globalUrl + data.data;
              that.setData({
                avatarUrl: avatarUrl
              })
            } else {
              wx.showModal({
                title: '错误',
                content: data.message
              })
            }
          }.bind(this),
          complete: function () {
            wx.hideLoading();
          }
        });
      }.bind(this)
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})